import fetch from '@/utils/request';

const API_ADDRESS_URL = '/api/user/receiver';
/**
 * 地址API对象
 * @module AddressApi
 */
const AddressApi = {
	/**
	 * @function query
	 * @description 查询地址
	 * @param  {Object} query 查询参数对象
	 * @param  {Object} param 分页参数对象
	 */
	query: (query, param) => fetch.request({
		url: `${API_ADDRESS_URL}/query`,
		method: 'POST',
		data: {
			query: query,
			param: param
		},
	}),
	/**
	 * @function save
	 * @description 添加地址
	 * @param  {Object} address 地址对象
	 */
	save: (address) => fetch.request({
		url: `${API_ADDRESS_URL}/save`,
		method: 'POST',
		data: {
			receiver: address,
		},
	}),
	/**
	 * @function delete
	 * @description 删除地址
	 * @param  {String} id 地址对象id
	 */
	delete: (id) => fetch.request({
		url: `${API_ADDRESS_URL}/delete`,
		method: 'POST',
		data: {
			id: id,
		},
	}),
	/**
	 * @function get
	 * @description 得到地址
	 * @param  {String} id 地址对象id
	 */
	get: (id) => fetch.request({
		url: `${API_ADDRESS_URL}/get?id=${id}`,
		method: 'GET',
	}),
	/**
	 * @function get_def
	 * @description 得到默认地址
	 */
	get_def: () => fetch.request({
		url: `${API_ADDRESS_URL}/def`,
		method: 'GET',
	}),
	/**
	 * @function set_def
	 * @description 设置默认地址
	 * @param  {String} id 地址对象id
	 */
	set_def: (id) => fetch.request({
		url: `${API_ADDRESS_URL}/def`,
		method: 'POST',
		data: {
			id: id,
		},
	}),
};
export default AddressApi;